package org.lgiavedoni.android.franq.command.general;

import java.util.List;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;
import org.lgiavedoni.android.franq.core.calendar.Calendar;
import org.lgiavedoni.android.franq.core.command.Command;
import org.lgiavedoni.android.franq.service.communication.CommunicationService;
import org.lgiavedoni.android.franq.service.phone.calendar.CalendarService;
import org.lgiavedoni.android.franq.util.collection.CollectionUtils;

public class CalendarCommand extends Command {

	private static final String OPTION_LIST = "list";

	@Override
	public void setOptions(Options options) {
		options.addOption(OPTION_LIST, false, "List all calendars");
	}

	@Override
	public boolean execute(CommandLine cmd) {
		if (cmd.hasOption(OPTION_LIST)) {
			List<Calendar> contacts = CalendarService.inst.getCalendars();
			CommunicationService.inst.sendDefaultTextMessage("Calendars: \n" + CollectionUtils.toString(contacts, " - "));
			return true;
		}
		return false;
	}

	@Override
	public String getCommandText() {
		return "calendar";
	}
}